bitkeeper revision 1.816 (405eedfdtQSsv_FQddod4l3qGl-RuA)
authorkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Mon, 22 Mar 2004 13:45:33 +0000 (13:45 +0000)
committerkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Mon, 22 Mar 2004 13:45:33 +0000 (13:45 +0000)
xencons:
  new file
Makefile, Xeno-HOWTO.txt, README.CD:
  Install an easily-accessible console terminal client program.

.rootkeys
README.CD
docs/Xeno-HOWTO.txt
tools/misc/Makefile
tools/misc/xencons [new file with mode: 0755]

index 9d48129acb725226615a503c66d69d9e7d0dd677..c6fe3694bb008337d422481b5332f580f02c1a28 100644 (file)
--- a/.rootkeys
+++ b/.rootkeys
@@ -64,6 +64,7 @@
 3f8bcf29ulZIC9rC4wM70H_q4s6VPg tools/misc/xen_log.c
 3f13d81eQ9Vz-h-6RDGFkNR9CRP95g tools/misc/xen_nat_enable
 3f13d81e6Z6806ihYYUw8GVKNkYnuw tools/misc/xen_nat_enable.README
+405eedf6_nnNhFQ1I85lhCkLK6jFGA tools/misc/xencons
 4056f5155QYZdsk-1fLdjsZPFTnlhg tools/misc/xensymoops.py
 4022a73cEKvrYe_DVZW2JlAxobg9wg tools/nsplitd/Makefile
 4022a73cKms4Oq030x2JBzUB426lAQ tools/nsplitd/nsplitd.c
index 0301030c64c29184f38b3436ac351f9bc84bd555..a387d0694ece8f79594370a8e1d1b6155dd5a959 100644 (file)
--- a/README.CD
+++ b/README.CD
@@ -203,11 +203,13 @@ have e.g.:
 
 xc_dom_create.py will print the local TCP port to which you should
 connect to perform console I/O. A suitable console client is provided
-by the Python module xend.console_client: running this module from the
-command line with <host> and <port> parameters will start a terminal
-session. An alternative is to specify '-c' to xc_dom_create.py, or add
+by the Python module xenctl.console_client: running this module from
+the command line with <host> and <port> parameters will start a
+terminal session. This module is also installed as /usr/bin/xencons,
+from a copy in tools/misc/xencons.  An alternative to manually running
+a terminal client is to specify '-c' to xc_dom_create.py, or add
 'auto_console=True' to the defaults file. This will cause
-xc_dom_create.py to automatically become teh console terminal after
+xc_dom_create.py to automatically become the console terminal after
 starting the domain.
 
 The 169.254.x.x network is special in that it is the 'link local'
index b3ed0217bf42a55780bf1ca48604639620973441..7f3ad7297d2c18bec22a056ccff2ce3525feb341 100644 (file)
@@ -265,9 +265,11 @@ to create a separate configuration file for each domain you start.
 
 xc_dom_create.py will print the local TCP port to which you should
 connect to perform console I/O. A suitable console client is provided
-by the Python module xend.console_client: running this module from the
-command line with <host> and <port> parameters will start a terminal
-session. An alternative is to specify '-c' to xc_dom_create.py, or add
+by the Python module xenctl.console_client: running this module from
+the command line with <host> and <port> parameters will start a
+terminal session. This module is also installed as /usr/bin/xencons,
+from a copy in tools/misc/xencons.  An alternative to manually running
+a terminal client is to specify '-c' to xc_dom_create.py, or add
 'auto_console=True' to the defaults file. This will cause
 xc_dom_create.py to automatically become teh console terminal after
 starting the domain.
index 3db1b76fc085136cc610f954912637c1d170db53..c572e6d9a403420546a966ae562e27126a983db0 100644 (file)
@@ -10,7 +10,8 @@ OBJS     = $(patsubst %.c,%.o,$(SRCS))
 
 TARGETS  = xen_cpuperf
 
-INSTALL  = $(TARGETS) xen-mkdevnodes xen_nat_enable xen-clone xen_dmesg.py
+INSTALL  = $(TARGETS) xen-mkdevnodes xen_nat_enable xen-clone
+INSTALL += xen_dmesg.py xencons
 
 all: $(TARGETS)
        $(MAKE) -C miniterm
diff --git a/tools/misc/xencons b/tools/misc/xencons
new file mode 100755 (executable)
index 0000000..b826c89
--- /dev/null
@@ -0,0 +1,85 @@
+#!/usr/bin/env python
+
+##############################################
+# Console client for Xen guest OSes
+# Copyright (c) 2004, K A Fraser
+##############################################
+
+import errno, os, signal, socket, struct, sys
+
+from termios import *
+# Indexes into termios.tcgetattr() list.
+IFLAG  = 0
+OFLAG  = 1
+CFLAG  = 2
+LFLAG  = 3
+ISPEED = 4
+OSPEED = 5
+CC     = 6
+
+def __child_death(signum, frame):
+    global stop
+    stop = True
+
+def __recv_from_sock(sock):
+    global stop
+    stop = False
+    while not stop:
+        try:
+            data = sock.recv(1)
+            os.write(1, data)
+        except socket.error, error:
+            if error[0] != errno.EINTR:
+                raise
+    os.wait()
+
+def __send_to_sock(sock):
+    while 1:
+        data = os.read(0,1)
+        if ord(data[0]) == ord(']')-64:
+            break
+        try:
+            sock.send(data)
+        except socket.error, error:
+            if error[0] == errno.EPIPE:
+                sys.exit(0)
+            if error[0] != errno.EINTR:
+                raise
+    sys.exit(0)
+
+def connect(host,port):
+    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
+    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+    sock.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,
+                    struct.pack('ii', 0, 0))
+    sock.connect((host,port))
+
+    oattrs = tcgetattr(0)
+    nattrs = tcgetattr(0)
+    nattrs[IFLAG] = nattrs[IFLAG] & ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON)
+    nattrs[OFLAG] = nattrs[OFLAG] & ~(OPOST)
+    nattrs[CFLAG] = nattrs[CFLAG] & ~(CSIZE | PARENB)
+    nattrs[CFLAG] = nattrs[CFLAG] | CS8
+    nattrs[LFLAG] = nattrs[LFLAG] & ~(ECHO | ICANON | IEXTEN | ISIG)
+    nattrs[CC][VMIN] = 1
+    nattrs[CC][VTIME] = 0
+
+    if os.fork():
+        signal.signal(signal.SIGCHLD, __child_death)
+        print "************ REMOTE CONSOLE: CTRL-] TO QUIT ********"
+        tcsetattr(0, TCSAFLUSH, nattrs)
+        try:
+            __recv_from_sock(sock)
+        finally:
+            tcsetattr(0, TCSAFLUSH, oattrs)
+            print
+            print "************ REMOTE CONSOLE EXITED *****************"
+    else:
+        signal.signal(signal.SIGPIPE, signal.SIG_IGN)
+        __send_to_sock(sock)
+
+if __name__ == '__main__':
+    if len(sys.argv) != 3:
+        print sys.argv[0] + " <host> <port>"
+        sys.exit(1)
+    connect(str(sys.argv[1]),int(sys.argv[2]))